<style> 
    #uploadButton, .uploadButton {
        width: 108px;
        height: 28px;
        background-image: url(__PUBLIC__/dwz146/uploadify/img/uploadify-upload.png);
        display: block;
    }
    
    #urls dt {
        width: 250px;
    }
    
    #urls dl input {
        width: 220px;
    }
    
    /*.image .uploadify-button,.image .uploadify:hover .uploadify-button{
     background:none;
     border:none;
     }*/ 
</style>
<script type="text/javascript">
                                                	<?php $timestamp = time();?>
                                                	$(function() {
                                                		$('#file_upload').uploadify({
                                                			//校验数据
                                                			<php>
                                                			$timestamp=time();
                                                			</php>
                                                			'formData'     	: {
                                                				'timestamp' : '<?php echo $timestamp;?>',
                                                				'sess_id' : '<?php echo session_id();?>',
                                                				'token'     : '<?php echo md5('unique_salt' . $timestamp);?>'//声明令牌
                                                			},
                                                			'swf'         	:'__PUBLIC__/dwz146/uploadify/scripts/uploadify.swf',//指定上传控件的主体文件，默认‘uploader.swf’
                                                			'uploader'    	:'{:U("Content/file_uploads")}',//指定服务器端上传处理文件，默认‘upload.php’
                                                			'auto'        	:false,//手动上传
                                                			'scriptData': { 'sess_id': '<?php echo session_id();?>'},
                                                			'buttonImage' 	:'__PUBLIC__/dwz146/uploadify/img/uploadify-browse.png',//浏览按钮背景图片
                                                			'multi'       	:true,//单文件上传
                                                			'fileTypeExts'  :'*.gif; *.jpg; *.png; *.jpeg',//允许上传的文件后缀
                                                			'fileSizeLimit' :'300MB',//上传文件的大小限制，单位为B, KB, MB, 或 GB
                                                			'successTimeout':30,
                                                			'onUploadSuccess':function(file, data, response){
                                                				var html='<dl class="nowrap">';
                                                                html+='<dt><input type="text" name="picsname[]" value="'+file.name+'"></dt>';
                                                                html+='<dd><input name="pics[]" value="'+data+'" type="text"/> <a target="_blank" href="'+data+'" rel="filename">查看</a></dd>';
                                                                html+='</dl>';
                                                	            $('#urls').append(html);
                                                	        },
                                                	        'onUploadError':function(file, data, response){
                                                	            $('#urls').append("<li>"+data+"</li>");
                                                	        },
                                                		});
                                                		
                                                		$("#upimagebnt").uploadify({
                                                			'swf'         	:'__PUBLIC__/dwz146/uploadify/scripts/uploadify.swf',
                                                			'uploader'    	:'{:U("Content/file_upload")}',
                                                			'auto'        	:true,
                                                			'formData'     	: {
                                                				'sess_id' : '<?php echo session_id();?>',
                                                			},
                                                			'fileTypeExts'  :'*.gif; *.jpg; *.png; *.jpeg',
                                                			'fileSizeLimit' :'300KB',//上传文件的大小限制，单位为B, KB, MB, 或 GB
                                                			'successTimeout':30,
                                                			//'buttonClass':'uploadButton',
                                                			'buttonText':'上传文件',
                                                			'multi'         :false,//单文件上传
                                            				'width'    : 60,
                                            				'height': 18,
                                                			'onUploadSuccess':function(file, data, response){
                                                				$("#upimage").val(data);
                												$("#main_img").attr("src",data);
                                                				//html=' <a target="_blank" href="'+data+'">查看</a>';
                                                				//$('#upimagedd').append(html);
                                                	        },
                                                	        'onUploadError':function(file, data, response){
                                                				alert(data+'上传失败，请重试');
                                                	        }
                                                		});
                                                	});
</script>
<div class="pageContent">
    <form method="post" id="Content_insert" action="{:U('Content/insert',array('proid'=>$proid))}" onsubmit="return validateCallback(this,navTabAjaxDone);">
        <div class="pageFormContent" layoutH="52">
            <div class="tabs" currentIndex="0" eventType="click">
                <div class="tabsHeader">
                    <div class="tabsHeaderContent">
                        <ul>
                            <li>
                                <a href="javascript:;"><span>基本信息</span></a>
                            </li>
                            <li>
                                <a href="javascript:;"><span>图片</span></a>
                            </li>
                           <!--
						    <li>
                                <a href="javascript:;"><span>属性设置</span></a>
                            </li>
							-->
                            <li>
                                <a href="javascript:;"><span>产品属性</span></a>
                            </li>
							<li>
                                <a href="javascript:;"><span>附属分类</span></a>
                            </li>
                        </ul>
                    </div>
                </div>
                <div class="tabsContent" layoutH="82">
                    <div id="product_base">
                        <dl class="nowrap">
                            <dt>
                                <label>
                                    产品名称：
                                </label>
                            </dt>
                            <dd>
                                <input id='proid' type='hidden' name='base[id]' value='{$proid}' class="required" /><input name="base[name]" class="autoinput required" value="{$product['base']['name']}" type="text" style="width:350px;" />
                            </dd>
                        </dl>
                        <dl class="nowrap">
                            <dt>
                                <label>
                                    品牌：
                                </label>
                            </dt>
                            <dd>
                                <input id="inputBrand1" name="brand.id" value="{$brand.id}" type="hidden"/><input class="required" name="brand.name" value="{$brand.name}" type="text" postField="keywords" suggestFields="id,name" suggestUrl="{:U('Content/suggest',array('tn'=>'product_brand','fn'=>'id,name'))}" lookupGroup="brand"/>
								<a class="btnLook" href="{:U('Brand/lookup',array('tn'=>'product_brand','fn'=>'id,name'))}" lookupGroup="brand">查找品牌</a>
                                <span class="info">查找品牌</span>
                            </dd>
                        </dl>
                        <dl class="nowrap">
                            <dt>
                                <label>
                                    分类：
                                </label>
                            </dt>
                            <dd>
                                <input id="inputcate1" name="cat.id" value="{$catid}" type="hidden"/><input class="required" name="cat.name" value="{$catinfo.name}" type="text" postField="keywords" suggestFields="id,name" suggestUrl="{:U('Content/suggest',array('tn'=>'product_category_tag','fn'=>'id,name'))}" lookupGroup="cat"/>
								<a class="btnLook" href="{:U('Cat/lookup',array('tn'=>'product_category_tag','fn'=>'id,name'))}" lookupGroup="cat">查找分类</a>
                                <span class="info">查找分类</span>
                            </dd>
                        </dl>
						
			 
                        <dl class="nowrap">
                            <dt>
                                <label>
                                    产品编码：
                                </label>
                            </dt>
                            <dd>
                                <input name="base[code]" readonly="readonly" value="{$product['base']['code']}" type="text"/><span class="info">产品编码为空将自动生成编码(不可修改)</span>
                            </dd>
                        </dl>
                      <!--
					    <dl class="nowrap">
                            <dt>
                                <label>
                                    条形码：
                                </label>
                            </dt>
                            <dd>
                                <input name="base[ean13]" class="autoinput" value="{$product['base']['ean13']}" type="text"/><span class="info">条形码</span>
                            </dd>
                        </dl>
						-->
                        <dl class="nowrap image">
                            <dt>
                                <label>
                                    产品缩略图：
                                </label>
                            </dt>
                            <dd id="upimagedd">
                                {if $product['base']['image']}
                  
                                <img id="main_img" src='{$product['base']['image']|addrimage}' />
                            
                                <br/>
                                {/if}
								<input name="base[image]" id="upimage" value="{$product['base']['image']}" type="text"/><span class="info"><input id="upimagebnt" type="file"/></span>
                            </dd>
                        </dl>
                        <dl class="nowrap">
                            <dt>
                                <label>
                                    状态：
                                </label>
                            </dt>
                            <dd>
                                <select name="status" disabled="true">
                                    <option value="0">上下架状态</option>
                                    <option value="1" {if $product['base']['status']==1}  selected="selected" {/if}>上架</option>
                                    <option value="0" {if $product['base']['status']==0}  selected="selected" {/if}>下架</option>
                                </select>
                            </dd>
                        </dl>
						     <dl class="">
                            <dt>
                                <label>
                                   模型：
                                </label>
                            </dt>
                            <dd>
                                <select name="base[mname]" >
                                    <option value="0">请选择</option>
									<volist name='modelname' id='mn'>
                                    <option value="{$mn.value}" {if $product['base']['mname']== $mn['value']} selected="selected" {/if} >{$mn.title}</option>
									</volist>
                                   
                                </select>
                            </dd>
                        </dl>
                        <div class="unit">
                        </div>
                        <div class="unit">
                            <p style="width:100%;">
                                产品描述：
                            </p>
                            <textarea class="editor" upImgUrl="{:U('Content/upload')}" upImgExt="jpg,jpeg,gif,png" name="des[description]" rows="20" cols="130">
                                {$product.des.description|addrimage}
                            </textarea>
                        </div>
                        <div class="unit">
                            <p style="width:100%;">
                                规格描述：
                            </p>
                            <textarea class="editor" upImgUrl="{:U('Content/upload')}" upImgExt="jpg,jpeg,gif,png" name="des[property_description]" rows="20" cols="130">
                                {$product['des']['property_description']}
                            </textarea>
                        </div>
                        <dl class="nowrap">
                            <dt>
                                <label>
                                    产品别名：
                                </label>
                            </dt>
                            <dd>
                                <input name="des[alias]" value="{$product['des']['alias']}" type="text"/>
                            </dd>
                        </dl>
                        <dl class="nowrap">
                            <dt>
                                <label>
                                    关键描述：
                                </label>
                            </dt>
                            <dd>
                                <input name="des[meta_description]" value="{$product['des']['meta_description']}" type="text"/>
                            </dd>
                        </dl>
                        <dl class="nowrap">
                            <dt>
                                <label>
                                    关键字：
                                </label>
                            </dt>
                            <dd>
                                <input name="des[meta_keyword]" value="{$product['des']['meta_keyword']}" type="text"/>
                            </dd>
                        </dl>
                    </div>
                    <div id="product_img">
                        <fieldset>
                            <legend>
                                图片上传
                            </legend>
                            <!-- 原有的组图。 -->{if $product['groupimage']}
                            <div>
                                <volist name='product.groupimage' id='gimg'>
                                    <div id='gimg{$gimg.id}'>
                           
                                        <img src='{$gimg.url|addrimage}' style='width:150px;height:150px;'/>
                                  
                                        组图 {$key+1} <!--<a href="{:U('Content/del_groupimg',array('id'=>$gimg.id))}" target="ajaxTodo" title="确定要删除吗?">删除</a>--><a href='#' class='del_gimg' gimgid="{$gimg.id}">删除 </a>
                                        <br/>
                                    </div>
                                </volist>
                            </div>
                            {/if}<!-- end 原有的组图。 -->
                            <div id="urls">
                            </div>
                            <dl class="nowrap">
                                <dt>
                                </dt>
                                <dd>
                                    <input id="file_upload" name="file_upload" type="file" multiple="true"><a href="javascript:$('#file_upload').uploadify('upload','*')" id="uploadButton"></a>
                                </dd>
                            </dl>
                        </fieldset>
                    </div>
					
					<!--
                    <div id="product_attr">
                        <select class="combox" name="province" ref="w_combox_city" refUrl="{:U('Content/suggest',array('tn'=>'Attribute','fn'=>'id,name'))}&name={value}">
                            <option value="0">模型名称</option>
                            <volist name="modelname" id="mn">
                                <option value="{$mn['value']}">{$mn['title']}</option>
                            </volist>
                        </select>
                        <div class="divider" style="clear:both;">
                        </div>
                        <dl style="clear:both; height:auto;">
                            <dt>
                                <label>
                                </label>
                            </dt>
                            <dd style="height:auto;">
                                <div class="button">
                                    <div class="buttonContent">
                                        <button type="button" class="add_attr" rel="1">
                                            添加一个属性(下拉)
                                        </button>
                                    </div>
                                </div>
                                <div class="button">
                                    <div class="buttonContent">
                                        <button type="button" class="add_attr2" rel="1">
                                            添加一个属性(填写)
                                        </button>
                                    </div>
                                </div>
                            </dd>
                        </dl>
                        <div class="divider" style="clear:both;">
                        </div>
                        <div id="add_attr">
                        </div>
                    </div>
					-->
					
					
                    <div id="product_attr">

                        <fieldset>
                            <legend>
                                产品添加属性
                            </legend>
                            <div id="urls">
                            </div>
                            <dl class="nowrap">
                                <div class="tabs" currentIndex="0" eventType="click">
                                    <div class="tabsHeader">
                                        <div class="tabsHeaderContent">
                                            <ul>
                                                <volist name="modelname" id="mn">
                                                    <li>
                                                        <a href="javascript:;"><span>{$mn['title']}</span></a>
                                                    </li>
                                                </volist>
                                            </ul>
                                        </div>
                                    </div>
                                    <div class="tabsContent" layoutH="82">
                                       
									 <volist name="modelname" id="mn">
									    <div id="attrgroup_{$mn['value']}">
									    	
                               
                             
                                 
                                    <volist name='groupattr' id='gattr' key='key_num'>
                                        {if $gattr['modelname'] == $mn['value']}
										<fieldset>
                                            <legend>
                                               <!-- <input type='checkbox' class='checkall' disabled='true' idnum='{$key_num}' /> -->{$gattr.name} 
												<a id = "addattr" title="自定义属性" href="{:U('Content/addattr',array('gid'=>$gattr['id']))}" target="dialog" width="600" height="350"    ><span>++</span></a>
												
                                            </legend>
                                            <div>
                                                <volist name='gattr.attrs' id='attr'>
                                                    <input name='attrs[]' type='checkbox' class='chpro_{$key_num} {if $proid}updateattr{/if}' {if $proattr[$attr['id']]}checked='checked'{/if}  value='{$attr.id}' />
                                                    {$attr.value}

 &nbsp;&nbsp;
                                                </volist>
                                            </div>
                                        </fieldset>
										{/if}
                                    </volist>
                               
                                    </div>
									</volist>
                                  
                                </div>
                                </div>
                             
                            </dl>
                        </fieldset>
                    </div>
					
					
										
                    <div id="product_attr">

                        <fieldset>
                            <legend>
                                产品附属分类
                            </legend>
                            <div id="urls">
                            </div>
                            <dl class="nowrap">
                                <div class="tabs" currentIndex="0" eventType="click">
                                  
                                    <div class="tabsContent" layoutH="82">
                                       
									
									    <div id="attrgroup_{$mn['value']}">
									    	
                               
                             
                                 
                                    <volist name='catelist' id='cate' key='key_num'>
                                       
										<fieldset>
                                            <legend>
                                                <input type='checkbox' class='{if $proid}updatecate{/if}'  value='{$cate.id}' idnum='{$key_num}' {if $procates[$cate['id']]}checked='checked'{/if} />{$cate.name} 
												
												
                                            </legend>
                                            <div>
                                                <volist name='cate.child' id='child_1'>
                                                    <input name='cateids[]' type='checkbox' class='{if $proid}updatecate{/if}' {if $procates[$child_1['id']]}checked='checked'{/if}  value='{$child_1.id}' />
                                                    {$child_1.name}
													
													{if $child_1['child']}
													<font color='green'> ( </font>
													<volist name='child_1.child' id='child_2'>
														
														 <input name='cateids[]' type='checkbox' class='{if $proid}updatecate{/if}' {if $procates[$child_2['id']]}checked='checked'{/if}  value='{$child_2.id}' />
                                                    <font color='green'> {$child_2.name} </font>
													</volist>
													<font color='green'> ) </font>&nbsp;&nbsp;
													{/if}

 &nbsp;&nbsp;
                                                </volist>
												
                                            </div>
                                        </fieldset>
										
                                    </volist>
                               
                                    </div>
									
                                  
                                </div>
                                </div>
                             
                            </dl>
                        </fieldset>
                    </div>
					
					
                </div>
            </div>
        </div>

        <div class="formBar">
            <ul>
                <li>
                    <div class="buttonActive">
                        <div class="buttonContent">
                            <button type="submit" onclick="return validateCallback($('#Content_insert'),navTabAjaxDone);">
                                保存
                            </button>
                        </div>
                    </div>
                </li>
                <li>
                    <div class="button">
                        <div class="buttonContent">
                            <button type="button" class="close">
                                取消
                            </button>
                        </div>
                    </div>
                </li>
            </ul>
        </div>
    </form>
</div>
<script>
    $(function(){
		
		//全选
		$('.checkall').click(function(){
			var idnum = $(this).attr('idnum');
			var cked = $(this).attr('checked');
			
			 $('.chpro_'+idnum).each(function(){
                if (cked) {
                    $(this).attr('checked', true);
                }
                else {
                    $(this).attr('checked', false);
                }
            });
		});
		
		//ajax 修改产品属性
		$('.updateattr').click(function(){
			var attrid = $(this).val();
			var proid = $("#proid").val();
			var cked = $(this).attr('checked');
			url = "{:U('Content/ajax_updateattr')}";
			$.ajax({
                type: "get",
                url: url+"&attrid=" + attrid+"&proid="+proid+"&ched="+cked,
                success: function(msg){
					
				}
        	});
		});
		
		//ajax 修改产品分类
		$('.updatecate').click(function(){
			var cateid = $(this).val();
			var proid = $("#proid").val();
			var cked = $(this).attr('checked');
			url = "{:U('Content/ajax_updatecate')}";
			$.ajax({
                type: "get",
                url: url+"&cateid=" + cateid+"&proid="+proid+"&ched="+cked,
                success: function(msg){
					
				}
        	});
		});
		
        
        //删除组图
        $(".del_gimg").click(function(){
            var id = $(this).attr('gimgid');
            //定义处理方法    
            var _submitFn = function(){
                var url = "{:U('Content/del_groupimg')}";
                $.post(url, {
                    id: id
                }, function handel(res){
                    if (res) {
                        $("#gimg" + id).hide();
                    }
                });
            }
            //确认是否删除
            alertMsg.confirm('确定删除?', {
                okCall: _submitFn
            });
            
        });
        
		//添加属性
		$("#addattr").click(function(){
			//$("#test").show();
			
		});
        
    });
</script>
